package yawning.mew.equipment;

public abstract class ItemSource {
	public static void pushFront(ItemSource s) {
		s.mNext = sFirst;
		sFirst = s;
	}

	public static void pushBack(ItemSource s) {
		if (sFirst == null) sFirst = s;
		else {
			ItemSource is = sFirst;
			while (is.mNext != null) is = is.mNext;
			is.mNext = s;
		}
	}

	public static RawItem getItem(int id) {
		return getItem(id, false);
	}

	public static RawItem getItem(int id, boolean allowNull) {
		sExceptions = new StringBuilder();
		RawItem i = sFirst.getById(id);
		if (i == null) {
			if (allowNull) {
				return new RawItem(id, null);
			} else
				throw new RuntimeException(sExceptions.toString());
		}
		return i;
	}

	private static ItemSource sFirst;
	protected static StringBuilder sExceptions;

	protected ItemSource mNext;
	protected abstract RawItem getById(int id);
}
